import Vue from 'vue'
import './plugins/axios'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/loading'
import vcharts from 'v-charts'
import animated from 'animate.css'
import VuCountryIntl from 'vue-country-intl';
import 'vue-country-intl/lib/vue-country-intl.css';
import '@/styles/vue-country-intl.css'
import i18n from './i18n'

Vue.config.productionTip = false;
// Vue.prototype.api = 'http://192.168.0.106:8082/index.php/home/';
Vue.prototype.api = 'https://api.fxtradelink.com/index.php/home/';
Vue.use(vcharts);
Vue.use(animated);

Vue.component(VuCountryIntl.name, VuCountryIntl);
Vue.prototype.onlyCountry = [
    'bn',
    'cn',
    'hk',
    'id',
    'kh',
    'la',
    'mm',
    'mo',
    'my',
    'ph',
    'sg',
    'th',
    'tl',
    'tw',
    'vn',
]
Vue.prototype.locales = [
    {
        code: 'zh-CN',
        lang: '中文'
    },
    {
        code: 'en',
        lang: 'English'
    }
]

Vue.prototype.logout = function () {
    const t = {
        "yes": this.$t('btn.yes'),
        "no": this.$t('btn.no'),
        "msg": this.$t('msg.logout'),
    }
    swal({
        title: t.msg,
        icon: 'info',
        buttons: {
            ok: {
                text: t.yes,
                className: 'btn btn-light waves-effect',
            },
            rt: {
                text: t.no,
                className: 'btn btn-gradient',
            }
        }
    }).then((value) => {
        if (value === 'ok') {
            this.$store.commit('logout');
            this.$router.push('login')
        }
    })
};

Vue.prototype.lang = function () {
    for (let i = 0; i < this.locales.length; i++) {
        let _locale = this.locales[i];
        if (_locale.code === store.state.locale) return _locale.lang;
    }
    return this.locales[0].lang;
};

Vue.prototype.changeLocale = function (locale) {
    this.$store.commit('changeLocale',locale);
    // i18n.locale = store.state.locale;
    window.location.reload();
};

new Vue({
    router,
    store,
    i18n,
    render: h => h(App)
}).$mount('#app')
